package main

import (
	"fmt"
	"sync"
)

type Info struct {
	mu  sync.Mutex
	Str string
	Cnt int
}

func UpdateStr(info *Info, str string) {
	info.mu.Lock()
	info.Str = str
	info.Cnt += 1
	info.mu.Unlock()
}

func main() {
	var wg sync.WaitGroup
	info := new(Info)
	strs := []string{"zhongli", "hutao", "ganyu"}
	wg.Add(len(strs))
	for _, s := range strs {
		go func(info *Info, str string, w *sync.WaitGroup) {
			defer w.Add(-1)
			UpdateStr(info, str)
		}(info, s, &wg)
	}
	fmt.Println("wait")
	wg.Wait()

	fmt.Println("info change time: ", info.Cnt)
	fmt.Println("info str: ", info.Str)
}
